const mysql = require("mysql");

let pool = mysql.createPool({
    host: '127.0.0.1',
    user: 'root',
    password: 'root',
    database: 'maiyawang',
    port: 3306,
    connectionLimit: 10
});

const exec = (sql, pramas) => {
    return new Promise((resolve, reject) => {
        pool.getConnection((err, conn) => {
            if (err) {
                console.log("数据库连接失败:" + err);
                reject(err)
            }
            conn.query(sql, pramas, (err, result) => {
                if (err) {
                    console.log("SQL语句执行失败:" + err);
                    reject(err);
                }
                resolve(result);
                conn.release();//释放链接 
            });
        })
    })
}

module.exports = {
    exec
}